﻿using System;
using System.Collections.Generic;
using VideoStore.Domain.DAL;
using VideoStore.Domain.Entities;

namespace VideoStore.Business
{
    public class CatalogueBusinessObject
    {
        #region Fields

        private readonly ICatalogueDataAccess catalogueDao;

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="CatalogueBusinessObject"/> class.
        /// </summary>
        public CatalogueBusinessObject()
        {
            catalogueDao = new CatalogueDataAccess();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CatalogueBusinessObject"/> class.
        /// </summary>
        /// <param name="dao">The DAO.</param>
        public CatalogueBusinessObject(ICatalogueDataAccess dao)
        {
            // This constructor enables easy TDD as it takes whatever IStockDataAccess implementation.
            catalogueDao = dao;
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Gets the video by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public Catalogue GetVideoById(int id)
        {
            Catalogue catalogue;
            try
            {
                catalogue = catalogueDao.GetVideoById(id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return catalogue;
        }

        /// <summary>
        /// Gets the video by genre.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        public IEnumerable<Catalogue> GetVideosByGenre(string name)
        {
            IEnumerable<Catalogue> catalogues;
            try
            {
                catalogues = catalogueDao.GetVideosByGenre(name);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return catalogues;
        }

        /// <summary>
        /// Gets the video by number.
        /// </summary>
        /// <param name="number">The number.</param>
        /// <returns></returns>
        public Catalogue GetVideoByNumber(string number)
        {
            Catalogue catalogue;
            try
            {
                catalogue = catalogueDao.GetVideoByCatalogueNumber(number);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return catalogue;
        }

        /// <summary>
        /// Gets the videos by director.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        public IEnumerable<Catalogue> GetVideosByDirector(string name)
        {
            IEnumerable<Catalogue> catalogues;
            try
            {
                catalogues = catalogueDao.GetVideosByDirector(name);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return catalogues;
        }

        /// <summary>
        /// Creates the video.
        /// </summary>
        /// <param name="newVideo">The new video.</param>
        /// <returns></returns>
        public Catalogue CreateVideo(Catalogue newVideo)
        {
            Catalogue catalogue;
            try
            {
                catalogue = catalogueDao.CreateVideo(newVideo);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return catalogue;
        }

        #endregion

    }
}
